// hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime.js
var app = getApp()
var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
var Y = date.getFullYear();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    server: "",
    dex: 0,
    times: ["19:00-20:00", "20:00-21:00", "20:00-21:00", "20:00-21:00"]
  },
  // 选择时间
  getdate(e) {
    var that = this
    var index = e.currentTarget.dataset.i
    var list_wedate = that.data.list_wedate
    var week = e.currentTarget.dataset.week
    var day = e.currentTarget.dataset.day
    var keywords = that.data.server
    console.log(that.data.server)
    for (var i = 0; i < list_wedate.length; i++) {
      if ([i] == index) {
        list_wedate[i].active = true
      } else {
        list_wedate[i].active = false
      }
    }
    var month = that.data.month
    if (month == '一月') {
      var month = '01'
    } else if (month == '二月') {
      var month = '02'
    } else if (month == '三月') {
      var month = '03'
    } else if (month == '四月') {
      var month = '04'
    } else if (month == '五月') {
      var month = '05'
    } else if (month == '六月') {
      var month = '06'
    } else if (month == '七月') {
      var month = '07'
    } else if (month == '八月') {
      var month = '08'
    } else if (month == '九月') {
      var month = '09'
    } else if (month == '十月') {
      var month = '10'
    } else if (month == '十一月') {
      var month = '11'
    } else if (month == '十二月') {
      var month = '12'
    }

    app.util.request({
      'url': 'entry/wxapp/zhuanjia.alldocservertime',
      data: {
        zid: that.data.zid,
        week: week,
        keywords: keywords
      },
      success: function (res) {
        console.log(res)

        if (res) {
          that.setData({
            time: res.data
          })
        }

      }
    })

    this.setData({
      list_wedate: list_wedate,
      month: that.data.month,
      time_date: Y + '-' + month + '-' + day,
      day: '周' + list_wedate[index].week
    })
  },
  seltime(e) {
    var that = this
    var time_leng = that.data.time_leng
    let times = e.currentTarget.dataset.time;
    var time_date = this.data.time_date
    var day = this.data.day
    var zongTime = time_date + ' ' + times + ' ' + day
    var money = that.data.money
    var zid = that.data.zid
    var key_words = that.data.server
    var addnum = that.data.addnum
    var privateNum = that.data.privateNum

    var nums = parseInt(e.currentTarget.dataset.nums);
    var yynum = parseInt(e.currentTarget.dataset.yynum);
    console.log(this.data.server);
    if (nums == yynum) {
      wx.showToast({
        title: '预约已满',
        icon: 'none',
      })
      return false;
    }
    if (this.data.server == 'tijianjiedu') {
      wx.navigateTo({
        url: '/hyb_yl/backstageServices/pages/noreport/noreport?server=' + key_words + '&times=' + zongTime + '&zid=' + zid + '&money=' + money + '&time_leng=' + time_leng + '&addnum=' + addnum, //体检
      })
    } else if (this.data.server == 'tuwenwenzhen') {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?server=' + key_words + '&times=' + zongTime + '&zid=' + zid + '&money=' + money + '&time_leng=' + time_leng + '&addnum=' + addnum, //图文问诊
      })
    } else if (this.data.server == 'shipinwenzhen' || this.data.server == 'dianhuajizhen') {
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/information/information?server=' + key_words + '&zongtime=' + zongTime + '&zid=' + zid + '&yearDate=' + time_date + '&day=' + day + '&times=' + times + '&money=' + money + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum, //手术预约
      })
    }else if (this.data.server == 'shoushukuaiyue' || this.data.server == 'yuanchengguahao') {
      
      wx.redirectTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?server=' + key_words + '&times=' + zongTime + '&zid=' + zid + '&money=' + money + '&time_leng=' + time_leng + '&addnum=' + addnum, //图文问诊
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var money = options.money
    var bgc = wx.getStorageSync('color')
    var time_leng = options.time_leng
    var addnum = options.addnum
    var privateNum = options.privateNum

    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    if(options.key_words != undefined)
    {
      var server = options.key_words;
    }else if(options.server != undefined){
      var server = options.server;
    }
    that.setData({
      zid: options.zid,
      server: server,
      money: money,
      time_leng: time_leng,
      addnum: addnum,
      privateNum: privateNum,
    })
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.timelist',
      data: {
        zid: options.zid
      },
      success: function (res) {
        console.log(res)
        res.data.timearr[0]['active'] = true
        var list_wedate = res.data.timearr
        that.setData({
          list_wedate: res.data.timearr,
          month: res.data.month,
        })
        var month = res.data.month
        if (month == '一月') {
          var month = '01'
        } else if (month == '二月') {
          var month = '02'
        } else if (month == '三月') {
          var month = '03'
        } else if (month == '四月') {
          var month = '04'
        } else if (month == '五月') {
          var month = '05'
        } else if (month == '六月') {
          var month = '06'
        } else if (month == '七月') {
          var month = '07'
        } else if (month == '八月') {
          var month = '08'
        } else if (month == '九月') {
          var month = '09'
        } else if (month == '十月') {
          var month = '10'
        } else if (month == '十一月') {
          var month = '11'
        } else if (month == '十二月') {
          var month = '12'
        }
        var day = list_wedate[0].time
        that.setData({
          time_date: Y + '-' + month + '-' + day,
          day: '周' + list_wedate[0].week
        })

        var week = res.data.timearr[0].week2
        app.util.request({
          'url': 'entry/wxapp/zhuanjia.alldocservertime',
          data: {
            zid: that.data.zid,
            week: week,
            keywords: options.key_words
          },
          success: function (res) {
            console.log(res)
            that.setData({
              time: res.data
            })
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})